﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// CreateTravelFlowPage.xaml 的交互逻辑
        /// </summary>
        public partial class CreateTravelFlowWindow
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public CreateTravelFlowWindow()
                {
                        InitializeComponent();
                }

                private void Window_Loaded(object sender, RoutedEventArgs e)
                {
                        _gm.StartTime = DateTime.Now;
                        _gm.EndTime = DateTime.Now;
                        _gm.ApproveEmployee = null;

                        LayoutRoot.DataContext = _gm;
                }

                private void Window_OnMouseDown(object sender, MouseButtonEventArgs e)
                {
                        if (e.ChangedButton == MouseButton.Left)
                        {
                                this.DragMove();
                        }
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        if (String.IsNullOrEmpty(_gm.TravelFlowPlanContent))
                        {
                                MessageBox.Show("计划不能为空");
                                return;
                        }

                        

                        try
                        {
                                TravelFlow travel = _gm.LoginEmployee.CreateTravelFlow(_gm.TravelFlowPlanContent,
                                                                                       _gm.TravelFlowLendAmount,
                                                                                       _gm.StartTime,
                                                                                       _gm.EndTime,
                                                                                       _gm.Memo,
                                                                                       _gm.ApproveEmployee.Id);
                                travel.Insert();

                                _gm.TravelFlows.Add(travel);
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }
Close();
                        
                }

        }
}